package cn.com.shopec.erp.product.service.impl;

import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Row;

import cn.com.shopec.erp.common.excel.ExcelBaseImport;
import cn.com.shopec.erp.product.entity.ProductStock;
import cn.com.shopec.erp.stock.commo.ObjectUtil;

public class ProductStockExcelImport extends ExcelBaseImport {

	/**
	 * 构造函数
	 * @param inputStream
	 * @param fileName
	 * @param beginRowIndex
	 * @throws IOException
	 */
	public ProductStockExcelImport(InputStream inputStream, String fileName,int beginRowIndex) throws IOException {
		super(inputStream, fileName,beginRowIndex);
	}

	@Override
	public ProductStock setColumnMapping(Row row) {
		ProductStock productStock = new ProductStock();
		row.getCell(0).setCellType(HSSFCell.CELL_TYPE_STRING);
		row.getCell(1).setCellType(HSSFCell.CELL_TYPE_STRING);
		row.getCell(2).setCellType(HSSFCell.CELL_TYPE_STRING);
		row.getCell(3).setCellType(HSSFCell.CELL_TYPE_STRING);
		productStock.setWhNo(ObjectUtil.toString(getCellData(row.getCell(0))));
		productStock.setSupNo(ObjectUtil.toString(getCellData(row.getCell(1))));
		productStock.setProdNo(ObjectUtil.toString(getCellData(row.getCell(2))));
		productStock.setCommoNo(ObjectUtil.toString(getCellData(row.getCell(3))));
		row.getCell(4).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		row.getCell(5).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		row.getCell(6).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		DecimalFormat df = new DecimalFormat("0");  		  
		productStock.setProductTotal(ObjectUtil.toLong(df.format(getCellData(row.getCell(4)))));
		productStock.setQualifiedQuantity(ObjectUtil.toLong(df.format(getCellData(row.getCell(5)))));
		productStock.setDefectiveQuantity(ObjectUtil.toLong(df.format(getCellData(row.getCell(6)))));
		//productStock.setPreOccupyQuantity(ObjectUtil.toLong(getCellData(row.getCell(7))));
		return productStock;
	}

}
